package top.linyuxb.lycloud.admin.repository;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import top.linyuxb.lycloud.admin.entity.LyConfClusterEntity;

import java.util.List;

/**
 * Created by Intellij IDEA.
 *
 * @Author: linyuxb
 * @Date: 2024/7/29 14:58
 * @Desc:
 */
@Repository
public interface LyConfClusterRepository extends BaseRepository<LyConfClusterEntity, Long> {
    /**
     * 全量查询
     * @param env
     * @param status
     * @return
     */
    List<LyConfClusterEntity> findByEnvAndStatusOrderByIdDesc(String env, Integer status);
    /**
     * 通过参数查询
     * @param env
     * @param clusterKey
     * @param status
     * @return
     */
    LyConfClusterEntity findByEnvAndClusterKeyAndStatus(String env, String clusterKey, Integer status);

    /**
     * 集群删除
     *
     * @param id
     * @return
     */
    @Modifying
    @Transactional
    @Query(value = "UPDATE ly_conf_cluster SET status = 0 WHERE id = ?1 and status = 1", nativeQuery = true)
    void deleteById(Long id);
}
